package com.edu.bhu.admin.service.impl;

import java.util.List;

import com.edu.bhu.common.constant.UserConstants;
import com.edu.bhu.common.core.domain.entity.SysUser;
import com.edu.bhu.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.bhu.admin.mapper.LibBookMapper;
import com.edu.bhu.admin.domain.LibBook;
import com.edu.bhu.admin.service.ILibBookService;
import com.edu.bhu.common.core.text.Convert;

/**
 * 图书Service业务层处理
 * 
 * @author wwb
 * @date 2022-02-11
 */
@Service
public class LibBookServiceImpl implements ILibBookService 
{
    @Autowired
    private LibBookMapper libBookMapper;

    /**
     * 查询图书
     * 
     * @param bookId 图书主键
     * @return 图书
     */
    @Override
    public LibBook selectLibBookByBookId(Long bookId)
    {
        return libBookMapper.selectLibBookByBookId(bookId);
    }

    /**
     * 查询图书列表
     * 
     * @param libBook 图书
     * @return 图书
     */
    @Override
    public List<LibBook> selectLibBookList(LibBook libBook)
    {
        return libBookMapper.selectLibBookList(libBook);
    }

    /**
     * 查询图书列表(关联图书类型)
     *
     * @param libBook 图书
     * @return 图书集合
     */
    public List<LibBook> selectLibBookWithTypeList(LibBook libBook)
    {
        return libBookMapper.selectLibBookWithTypeList(libBook);
    }

    /**
     * 查询图书列表(关联图书类型)(被删除的)
     *
     * @param libBook 图书
     * @return 图书集合
     */
    public List<LibBook> selectLibBookWithTypeListDel(LibBook libBook)
    {
        return libBookMapper.selectLibBookWithTypeListDel(libBook);
    }

    /**
     * 新增图书
     * 
     * @param libBook 图书
     * @return 结果
     */
    @Override
    public int insertLibBook(LibBook libBook)
    {
        return libBookMapper.insertLibBook(libBook);
    }

    /**
     * 修改图书
     * 
     * @param libBook 图书
     * @return 结果
     */
    @Override
    public int updateLibBook(LibBook libBook)
    {
        return libBookMapper.updateLibBook(libBook);
    }

    /**
     * 批量修改图书信息
     *
     * @return 结果
     */
    @Override
    public int updateLibBookBatch(String ids){
        return libBookMapper.updateLibBookBatch(Convert.toStrArray(ids));
    }


    /**
     * 图书状态修改
     *
     * @param libBook 图书信息
     * @return 结果
     */
    public int changeStatus(LibBook libBook)
    {
        return libBookMapper.updateLibBook(libBook);
    }

    /**
     * 批量删除图书
     * 
     * @param bookIds 需要删除的图书主键
     * @return 结果
     */
    @Override
    public int deleteLibBookByBookIds(String bookIds)
    {
        return libBookMapper.deleteLibBookByBookIds(Convert.toStrArray(bookIds));
    }

    /**
     * 删除图书信息
     * 
     * @param bookId 图书主键
     * @return 结果
     */
    @Override
    public int deleteLibBookByBookId(Long bookId)
    {
        return libBookMapper.deleteLibBookByBookId(bookId);
    }

    /**
     * 批量删除图书
     *
     * @param bookIds 需要删除的图书主键
     * @return 结果
     */
    @Override
    public int deleteLibBookByBookIdsForever(String bookIds)
    {
        return libBookMapper.deleteLibBookByBookIdsForever(Convert.toStrArray(bookIds));
    }

    /**
     * 删除图书信息
     *
     * @param bookId 图书主键
     * @return 结果
     */
    @Override
    public int deleteLibBookByBookIdForever(Long bookId)
    {
        return libBookMapper.deleteLibBookByBookId(bookId);
    }


    /**
     * 校验bookId是否唯一
     *
     * @param libBook
     * @return
     */
    @Override
    public String checkBookNoUnique(LibBook libBook)
    {
        Long bookId = StringUtils.isNull(libBook.getBookId()) ? -1L : libBook.getBookId();
        LibBook info = libBookMapper.checkBookNoUnique(libBook.getBookNo());
        if (StringUtils.isNotNull(info) && info.getBookId().longValue() != bookId.longValue())
        {
            return "1";
        }
        return "0";
    }
}
